const app = getApp();
const Controller = require('../controllers/controllers.js').controller;

Page({
  data: {
    userInfo:'',
    kfconcatnums:'',
    myDataCountdata:"",
  },
  onLoad: function (options) {
    if(options.parentid){
      app.globalData.parentid=options.parentid
    }
  },
  onShow: function () {
    if (!wx.getStorageSync('logintoken')) {
      app.ToLogin(true)
      app.tokenReadyCallback1 = res => {
        console.log(res)
        this.info()
        this.myDataCount()
      }
    }else{
      this.info()
      this.myDataCount()
    }
    // if (!wx.getStorageSync('logintoken')) {
    //   app.ToLogin(true)
    // }else{
    //   this.info()
    //   this.myDataCount()
    // }
    this.kfconcat()
  },
  info(){
    Controller.info().then(res=>{
      if(res.data.baseData){
        this.setData({
          userInfo:res.data.baseData
        })
      }
    })
  },
  myDataCount(){
    Controller.myDataCount().then(res=>{
      if(res.data.baseData){
        this.setData({
          myDataCountdata:res.data.baseData,
        })
      }
    })
  },
  kfconcat(){
    Controller.appinfo({key:"key-phone"}).then(res=>{
      if(res.data.baseData){
        this.setData({
          kfconcatnums:res.data.baseData.content
        })
      }
    })
  },
  golink(e){
    if (!wx.getStorageSync('logintoken')) {
      app.ToLogin(true)
      return
    }
    var url=e.currentTarget.dataset.url;
    wx.navigateTo({
      url: url
    })
  },
  concat(e){

    wx.showActionSheet({
      itemList: [e.currentTarget.dataset.tel,'呼叫'],
      success:function(res){
        if(res.tapIndex==1){
          wx.makePhoneCall({
            phoneNumber: e.currentTarget.dataset.tel,
          })
        }
      }
    })
  },
  onShareAppMessage: function (e) {
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
  onShareTimeline: function(res){
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
})